﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;

namespace Wangzeran.CodeMaker.Core.Tag
{
    /// <summary>
    /// 标签插件集合
    /// </summary>
    public class TagPlugIns
    {
        /// <summary>
        /// 已注册标签
        /// </summary>
        private static IDictionary<string, string> m_Tags = new Dictionary<string, string>();
        /// <summary>
        /// 已注册标签
        /// </summary>
        public static IDictionary<string, string> Tags
        {
            get { return m_Tags; }
            set { m_Tags = value; }
        }

        /// <summary>
        /// 注册标签
        /// </summary>
        /// <param name="tag">标签实例</param>
        public static void RegisterTag(ITag tag)
        {
            m_Tags.Add(tag.TagName, tag.ToString());
        }

        public static ITag InstanceTag(string tagName)
        {
            if (m_Tags.ContainsKey(tagName))
            {
                string typeName = m_Tags[tagName];
                if (typeName == null)
                {
                    return null;
                }
                Type t = Type.GetType(typeName);
                //ITag tag = (ITag)t.Assembly.CreateInstance(t.FullName); ;
                ITag tag = (ITag)Activator.CreateInstance(t);
                return tag;
            }
            else
            {
                return null;
            }
        }
    }
}
